/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package network;

import controllers.DatabaseController;
import java.io.IOException;
import java.net.ServerSocket;

/**
 *
 * @author gravena
 */
public class FileServer implements Runnable {
    public static final int FILE_TRANSFER_PORT = 45123;
    private ServerSocket conn;
    private DatabaseController dbController;
    
    public FileServer(DatabaseController dbController) {
        try {
            this.dbController = dbController;
            this.conn = new ServerSocket(FileServer.FILE_TRANSFER_PORT);
        } catch (IOException ex) {
            System.err.println("Erro na criação do socket.");
        }
    }
    
    @Override
    public void run() {
        while(true) {
            try {
                new Thread(new FileRequestHandler(conn.accept(),this.dbController)).start();
            } catch (IOException ex) {
                System.err.println("Erro no estabelecimento de conexão.");
            }
        }
    }
}
